package cn.jeeweb.web.modules.sys.service.impl;

import cn.jeeweb.common.mybatis.mvc.service.impl.TreeCommonServiceImpl;
import cn.jeeweb.common.utils.StringUtils;
import cn.jeeweb.web.modules.sys.entity.Organization;
import cn.jeeweb.web.modules.sys.mapper.OrganizationMapper;
import cn.jeeweb.web.modules.sys.mapper.UserMapper;
import cn.jeeweb.web.modules.sys.service.IOrganizationService;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Transactional
@Service("organizationService")
public class OrganizationServiceImpl extends TreeCommonServiceImpl<OrganizationMapper, Organization, String>
		implements IOrganizationService {


	@Override
	public List<Organization> findListByUserId(String userid) {
		return baseMapper.findListByUserId(userid);
	}

	@Override
	public List<Organization> findList(Organization organization) {
		return baseMapper.findList(organization);
	}

	/**
	 * 根据id获取机构名称
	 * @param id
	 * @return
     */
	@Override
	public String getOrganizationName(List<Organization> organizations,String id){
		if(StringUtils.isEmpty(id)){
			id = "";
		}
		String organizationName = "";
		if(organizations != null && organizations.size() > 0){
			for(Organization organization : organizations){
				if(id.equals(organization.getId())){
					organizationName = organization.getName();
					break;
				}
			}
		}
		return organizationName;
	}

}
